<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
<title>_作业信息查询</title>
<script type="text/javascript">
    var datatable_content;
	var filterParam={};
	
	$(function() {
		$("#queryForm").validate(); 
		$("#inputForm").validate(); //为inputForm注册validate函数
		$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
		$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
	});
	  
   	function initTable(){
   	datatable_content = $("#contentTable").dataTable({
		   "bServerSide":true,
		   "bAutoWidth":false,
           "sAjaxSource":'${ctx}/workMsg/v2_queryWorkMsg',
           "fnServerData": callback,
           "fnRowCallback":rowCallBack,
           "bFilter": false,
           "bSort": false,
           "sZeroRecords": "查询无记录！",
           "bProcessing": true,
           "oLanguage": {
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
             "aoColumns":[
             	 {"mData": null},
             	 {"mData": 'customer',
                	 "render": function (obj) {
                         return obj==null?'':obj.customerName;
                      }
                 },
                 {"mData": 'warehouse',
                	 "render": function (obj) {
                         return obj==null?'':obj.groupName;
                      }
                 },
             	 {"mData": "batchCode"},
             	 {"mData": null},
             	 {"mData": null},
             	 {"mData": null},
             	 {"mData": "orderQty"},
             	 {"mData": "creater.realname"},
             	 {"mData": 'createTime',
                	 "render": function (obj) {
                    	  var time=obj.time;
                         var date = new Date(time);
                         return date.Format("yyyy-MM-dd hh:mm");
                      }
               	 },
             	 {"mData": null},
             	 {"mData": null},
             ],
             "aoColumnDefs":[
             	{"aTargets": [4],
	              "mRender": function (data, display, row) {
						return row.pickType == "single" ? "单件":
							   row.pickType == "multi" ? "多件" : "";
		           }
	            },
	            {"aTargets": [5],
	              "mRender": function(data,display,row){
	              		return row.billType == "cbill" ? "普通运单":
	              			   row.billType == "ebill" ? "电子运单" : "";
	              }
	            },
	            {"aTargets": [6],
		              "mRender": function(data,display,row){
		              		return row.flowType == "prePrint" ? "预先打单":
		              			   row.flowType == "intimePrint" ? "及时打单" : "";
		              }
		        },
	            {"aTargets": [10],
	              "mRender": function(data,display,row){
	              		return row.status == "1" ? "已创建批次":
	              			   row.status == "2" ? "已创建任务":
	              			   row.status == "3" ? "已拣货":
	              			   row.status == "4" ? "已包装":
	              			   row.status == "5" ? "已发货": "";
	           	   }
	            },
	            
	            {"aTargets": [11],
	              "mRender": function(data,display,row){
	              		return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+ row.batchCode +"' role='button'  class='btn btn-primary' >查看详情</a>";
	           	   }
	            },
             ]
   		});
   	}
   	function callback(sSource, aoData, fnCallback ) {
   			
   	   aoData.push( { "name": "customerCode", "value": $("#_customerCode").val() } );  
   	   aoData.push( { "name": "warehouseCode", "value": $("#_warehouseCode").val() } );
   	   aoData.push( { "name": "batchCode", "value": $("#_batchCode").val() } );
   	   aoData.push( { "name": "fromDate", "value": $("#_fromDate").val() } );
   	   aoData.push( { "name": "toDate", "value": $("#_toDate").val() } );
   	   aoData.push( { "name": "taskCode", "value": $("#_taskCode").val() } );
   	   aoData.push( { "name": "orderno", "value": $("#_orderno").val() } );
   	   aoData.push( { "name": "status", "value": $("#_status").val() } );
   	   $.ajax({ 
   	       "type": "post",
   	       "contentType": "application/json", 
   	       "url": sSource,    
   	       "dataType": "json",   
   	       "data": JSON.stringify(aoData),
   	       "success": fnCallback  
   	   });
   	}
   	
   	/**
   	*创建了行的回调
   	*nRow为当前的tr
   	*/
   	function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
   		var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
   		$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
   	}
   	

   	function query() {
   		if ($("#queryForm").valid()) {
   			if (datatable_content) {
   				datatable_content.fnDestroy();
   			}
   			initTable();
   		}
   	}
    </script>
</head>

<body>
<section class="content">
    <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary" >
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
				<%-- <form class="form-search" id="queryForm" action="${ctx}/workMsg/v2_queryWorkMsg" method="post"> --%>
				<form class="form-search" id="queryForm" method="post">
				 <!-- 第一行 -->
					<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
							    <span class="input-group-text">商家名称:</span>
								 <select  class="form-control required" name="_customerCode"  id="_customerCode" value="${param._customerCode}"  onchange="ajaxAreaGroup(this,'_warehouseCode');">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
										<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
										>${customer.customerName}</option>
									</c:forEach>
								</select>
							 </div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text">作业仓库:</span>
								 <select  class="form-control required" name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  >
									<option value=""></option>
									<c:forEach items="${warehouseList}" var="wm">
										<option value="${wm.groupCode}"
										<c:if test="${param._warehouseCode eq wm.groupCode}">selected=selected</c:if>
										>${wm.groupName}</option>
									</c:forEach>
								</select>
							</div>
					</div>
						<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
								<span class="input-group-text">批次状态:</span>
								<!-- 批次状态 (1.已创建批次 2.已创建任务 3.已拣货 4.已包装  5.已发货) -->
								<select  class="form-control" id="_status" name="_status" >
								        <option value="" <c:if test="${param._status eq ''}">selected="selected"</c:if>>全选</option>
								        <option value="1" <c:if test="${param._status eq '1'}">selected="selected"</c:if>>已创建批次</option>
								        <option value="2" <c:if test="${param._status eq '2'}">selected="selected"</c:if>>已创建任务</option>
								        <option value="3" <c:if test="${param._status eq '3'}">selected="selected"</c:if>>已拣货</option>
								        <option value="4" <c:if test="${param._status eq '4'}">selected="selected"</c:if>>已包装</option>
								        <option value="5" <c:if test="${param._status eq '5'}">selected="selected"</c:if>>已发货</option>
								</select> 
								</div>
						</div>
						<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
								<span class="input-group-text">批次编号:</span>
								<input type="text" class="form-control" id="_batchCode" name="_batchCode" value="${param._batchCode}"/>
								</div>
						</div>
				</div>
				<div class="form-group row">
					<div class="col-sm-6">
						<div class="input-textgroup col-sm-12">
						<span class="input-group-text">创建时间:</span>
					 	<input type="text" name="_fromDate" id="_fromDate"  class="form-control" value="${param._fromDate}" /> 
					 	<span class="input-group-text">至：</span>
					 	<input type="text" name="_toDate" id="_toDate" class="form-control" value="${param._toDate}"  /> 
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">任务编号:</span>
						<input type="text" class="form-control" id="_taskCode" name="_taskCode" value="${param._taskCode}"/>
					</div>
				</div>
				<div class="col-sm-3">
					<div class="input-textgroup col-sm-12">
						<span class="input-group-text">订单编号:</span>
						<input type="text" class="form-control" id="_orderno" name="_orderno" value="${param._orderno}"/>
			 		</div>
			 	</div>
			 	</div>
			 	<div class="form-group row">
					<div class="col-sm-3">
						<div class="input-group col-sm-12">
			    <button type="button" onclick="query();" class="btn btn-info" >搜索</button>
			    </div>
			    </div>
			</div>
		</form>
		</div>
	  </div>
	 </div>
	</div>

	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>仓库编码</th>
			    <th>批次编号</th>
			    <th>订单类型</th>
			    <th>运单类型</th>
			    <th>作业模式</th>
			    <th>订单数量</th>
			    <th>创建人</th>
			    <th>创建时间</th>
			    <th>批次状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		<%-- <c:forEach items="${batchList}" var="workBatch" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${workBatch.customer.customerName}</td>
			   <td>${workBatch.warehouse.groupName}</td>
			   <td>${workBatch.batchCode}</td>
			   <td>
			     <c:if test="${workBatch.pickType eq 'single'}">单件</c:if>
			     <c:if test="${workBatch.pickType eq 'multi'}">多件</c:if>
			   </td>
			   <td>
			     <c:if test="${workBatch.billType eq 'cbill'}">普通运单</c:if>
			     <c:if test="${workBatch.billType eq 'ebill'}">电子运单</c:if>
			  </td>
			  <td>
			     <c:if test="${workBatch.flowType eq 'prePrint'}">预先打单</c:if>
			     <c:if test="${workBatch.flowType eq 'intimePrint'}">及时打单</c:if>
			  </td>
			   <td>${workBatch.orderQty}</td>
			   <td>${workBatch.creater.realname}</td>
			   <td>${fn:substring(workBatch.createTime,0,19)}</td>
			   <td>
			     <!-- 批次状态 (1.已创建批次 2.已创建任务 3.已拣货 4.已包装  5.已发货) -->
			     <c:if test="${workBatch.status eq '1'}">已创建批次</c:if>
			     <c:if test="${workBatch.status eq '2'}">已创建任务</c:if>
			     <c:if test="${workBatch.status eq '3'}">已拣货</c:if>
			     <c:if test="${workBatch.status eq '4'}">已包装</c:if>
			     <c:if test="${workBatch.status eq '5'}">已发货</c:if>
			   </td>
			   <td>
			      <a href="${ctx}/workMsg/v2_workMsgDetail/${workBatch.batchCode}" role="button"  class="btn btn-primary" >查看详情</a>
			   </td>
			</tr>
		</c:forEach> --%>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	</section>
</body>
</html>
